﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master_form.master" AutoEventWireup="true" CodeFile="diem_tnt.aspx.cs" Inherits="App_Form_DaoTao_diem_tnt" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript" src="../js/plugin/CellEditing.js"></script>

    <script type="text/javascript">
        Ext.Loader.setConfig({
            enabled: true
        });
        Ext.Loader.setPath('Ext.ux', '../ux');

        Ext.require(['*']);

        Ext.require([
    'Ext.selection.CellModel',
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.state.*',
    'Ext.form.*',
    'Ext.grid.Panel',
        'Ext.layout.container.Column'
        ]);


        Ext.onReady(function () {

            Ext.QuickTips.init();

            var bd = Ext.getBody();

            var gridForm = Ext.create('Ext.form.Panel', {
                id: 'company-form',
                frame: true,
                bodyPadding: 5,
                width: 1160,
                layout: {
                    type: 'table',
                    columns: 2
                },
                fieldDefaults: {
                    labelAlign: 'left',
                    msgTarget: 'side'
                },

                items: [
                    {
                        columnWidth: '100%',
                        margin: '0 0 0 10',
                        xtype: 'fieldset',
                        title: 'Thông tin môn học',
                        width: 1140,
                        width: 1120,
                        columnWidth: 1,
                        colspan: 2,
                        layout: 'anchor',
                        defaults: {
                            labelWidth: 100
                        },
                        defaultType: 'textfield',
                        items: [
                             {
                                 xtype: 'fieldcontainer',
                                 combineErrors: false,
                                 layout: {
                                     type: 'hbox',
                                     defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                 },
                                 defaults: {
                                     hideLabel: true
                                 },
                                 items: [
                                  { xtype: 'displayfield', width: 80, value: 'Năm học' },
                                 {
                                     width: 150, xtype: 'combo', value: 'I', emptyText: 'Chọn năm học',
                                     triggerAction: 'all', forceSelection: true, editable: false,
                                     id: 'nam_hoc', name: 'nam_hoc', displayField: 'ten',
                                     valueField: 'id',
                                     queryMode: 'local',
                                     store: null
                                 },

                                     { xtype: 'displayfield', width: 80, value: 'Hệ đào tạo' },
                                    {
                                        width: 150, xtype: 'combo',
                                        emptyText: 'Chọn hệ đào tạo', triggerAction: 'all', forceSelection: true,
                                        editable: false, id: 'he_dt', name: 'he_dt', displayField: 'Ten',
                                        valueField: 'ID', queryMode: 'local', store: null,
                                        listeners: {
                                            select: function (combo, record, index) {
                                                if (record.length > 0) {
                                                    var id_ht_dt = record[0].get('ID');
                                                    //Goi service
                                                    wtkb.Fjson_Khoa_Lke(id_ht_dt, khoa_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                                }
                                            }
                                        }
                                    },
                                { xtype: 'displayfield', width: 80, value: 'Khóa đào tạo' },
                                {
                                    width: 150, xtype: 'combo', triggerAction: 'all',
                                    emptyText: 'Chọn khóa', forceSelection: true,
                                    editable: false, id: 'khoa_dt',
                                    name: 'khoa_dt', displayField: 'Ten', valueField: 'ID',
                                    store: null,
                                    listeners: {
                                        select: function (combo, record, index) {
                                            if (record.length > 0) {
                                                var id_nganh = record[0].get('ID');
                                                //Goi service
                                                wtkb.Fs_LOP_KHOA(id_nganh, lophoc_nganh_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                            }
                                        }
                                    }
                                },
                                { xtype: 'displayfield', width: 30, value: 'Lớp' },
                                {
                                    width: 150,
                                    xtype: 'combo',
                                    value: '',
                                    emptyText: 'Chọn lớp',
                                    triggerAction: 'all',
                                    forceSelection: true,
                                    editable: false,
                                    id: 'lophoc',
                                    name: 'lop',
                                    displayField: 'ten_lop',
                                    valueField: 'id_lop',
                                    queryMode: 'local',
                                    store: null
                                },
                                {
                                    name: 'add',
                                    xtype: 'button',
                                    width: 80,
                                    icon: '../../shared/icons/fam/add.gif',
                                    text: 'Thêm mới',
                                    handler: function () {
                                        var b_nam = Ext.getCmp("nam_hoc").getValue(), b_hedt = Ext.getCmp("he_dt").getValue(), b_lop = Ext.getCmp("lophoc").getValue();
                                        var b_nam = Ext.getCmp("nam_hoc").getValue(), b_lop = Ext.getCmp("lophoc").getValue();
                                        var b_tinhdiem = Ext.getCmp('nhapdiem');
                                        var a_gtriGrid = new Array();
                                        var i = 0;
                                        b_tinhdiem.getStore().each(function (record) {
                                            if (NVL(record.get("ma_sv")) != " ") {
                                                a_gtriGrid[i] = [record.get("Id"), record.get("ma_sv"), record.get("MonID"), record.get("diem"), record.get("hso")];
                                                i++;
                                            }
                                        });
                                        wdkhp.Fs_SINHVIEN_TN_NH(b_nam, b_lop, b_hedt, a_gtriGrid, nhaodiemP_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                    }
                                },
                                 {
                                     name: 'tim',
                                     xtype: 'button',
                                     width: 80,
                                     icon: '../../shared/icons/fam/find.png',
                                     text: 'Tìm',
                                     handler: function () {
                                         var form = this.up('form').getForm()
                                         if (form.isValid()) {
                                             var lop = Ext.getCmp("lophoc").getValue();
                                             if (lop == "") return alert("Chưa chọn lớp");
                                             wdkhp.Fs_SINHVIEN_TN_TIM(lop, KB_TIM_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                         }
                                     }
                                 }
                                 ]
                             }]
                    },
                    {
                        columnWidth: '100%',
                        xtype: 'gridpanel',
                        margin: '5 0 0 10',
                        id: 'tinhdiem',
                        store: null,
                        width: 820,
                        height: 450,
                        layout: {
                            defaultMargins: { top: 0, right: 5, bottom: 0, left: 5 }
                        },
                        title: 'Danh sách học sinh',
                        columns: [
                            { id: 'ma_sv', text: 'Mã SV', width: 100, sortable: true, dataIndex: 'ma_sv' },
                            { id: 'hoten', text: 'Họ và tên', width: 150, flex: 1, sortable: true, dataIndex: 'hoten' },
                            { id: 'ngay_sinh', text: 'Ngày sinh', width: 80, flex: 1, sortable: true, dataIndex: 'ngay_sinh' },
                            { id: 'noi_sinh', text: 'Nơi sinh', width: 150, flex: 1, sortable: true, dataIndex: 'noi_sinh' }
                        ],

                        listeners: {
                            selectionchange: function (model, records) {
                                if (records[0]) {
                                    var b_masv = records[0].get("ma_sv");
                                    var lop = Ext.getCmp("lophoc").getValue(), nam = Ext.getCmp("nam_hoc").getValue();
                                    //Call service
                                    wdkhp.Fs_SINHVIEN_TN_CT(b_masv, lop, nam, lke_diem_P_LKE, P_LOI_CSDL, P_LOI_TGIAN);
                                    //this.up('form').getForm().loadRecord(records[0]);
                                }
                            }
                        }
                        // 
                    }, {
                        columnWidth: '40%',
                        xtype: 'gridpanel',
                        margin: '5 0 0 1',
                        id: 'nhapdiem',
                        store: null,
                        width: 300,
                        height: 450,
                        title: 'Nhập điểm',
                        plugins: Ext.create('Ext.grid.plugin.CellEditing', {
                            clicksToEdit: 1
                        }),
                        columns: [
                            { id: 'IDmon', flex: 1, hidden: true, hideable: false, dataIndex: 'Id' },
                            { id: 'IDmo', flex: 1, hidden: true, hideable: false, dataIndex: 'ma_sv' },
                            { id: 'IDmonthi', flex: 1, hidden: true, hideable: false, dataIndex: 'MonID' },
                            {
                                id: 'ten', text: 'Tên môn', flex: 1,
                                width: 150,
                                sortable: true,
                                dataIndex: 'tenmon'
                            },
                            {
                                text: 'Điểm',
                                width: 50,
                                sortable: true,
                                dataIndex: 'diem',
                                editor: {
                                    xtype: 'numberfield',
                                    decimalSeparator: '.',
                                    hideTrigger: true,
                                    allowBlank: false
                                }
                            },
                            { id: 'hs', flex: 1, hidden: true, hideable: false, dataIndex: 'hso' }
                        ]
                    }],
                renderTo: bd
            });
            wdkhp.Fs_NHAPDIEM_CH(P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
        function P_LOAD_TTCHUNG(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var a_kq = b_kq.split('@');
                var b_chuoi1 = CH_JSON(a_kq[0]),
                    b_chuoi2 = CH_JSON(a_kq[1]);
                //var a_kq = b_kq.split('@');
                //var b_chuoi3 = CH_JSON(a_kq[3]),
                //    b_chuoi5 = CH_JSON(a_kq[0]);;

                var a_data1 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'ten'],
                    data: b_chuoi1
                });
                //var a_data3 = Ext.create('Ext.data.Store', {
                //    fields: ['ten', 'id_nganhdt'],
                //    data: b_chuoi3
                //});

                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['Id_Nganh', 'TenNganh'],
                    data: b_chuoi2
                });
                //var a = Ext.getCmp('chuyen_nganh');
                //a.bindStore(a_data3);

                var b_chuoi4 = CH_JSON(a_kq[4]);
                var a_data4 = Ext.create('Ext.data.Store', {
                    fields: ['Ten', 'ID'],
                    data: b_chuoi4
                });
                //var a_data5 = Ext.create('Ext.data.Store', {
                //    fields: ['id', 'ten'],
                //    data: b_chuoi5
                //});

                //var cd = Ext.getCmp('nam_hoc');
                //cd.bindStore(a_data5);

                var a_kq = b_kq.split('@');
                var b_chuoi1 = CH_JSON(a_kq[0]),
                    b_chuoi2 = CH_JSON(a_kq[1]);

                var a_data1 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'ten'],
                    data: b_chuoi1
                });
                var b_hk = Ext.getCmp("he_dt");
                b_hk.bindStore(a_data4);

                var b_chuoi4 = CH_JSON(a_kq[4]);
                var a_data4 = Ext.create('Ext.data.Store', {
                    fields: ['Ten', 'ID'],
                    data: b_chuoi4
                });
                var b_hk = Ext.getCmp("he_dt");
                b_hk.bindStore(a_data4);

                var cd = Ext.getCmp('nam_hoc');
                cd.bindStore(a_data1);
                cd.bindStore(a_data1);


            }
        }
        function P_LOPNGANH_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi1 = CH_JSON(b_kq);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['id_lop', 'ten_lop'],
                    data: b_chuoi1
                });

                var b = Ext.getCmp('lop');
                b.clearValue();
                b.setValue("");
                b.setValue(null);
                b.bindStore(a_data2);
            }
        }
        function KB_TIM_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b = Ext.getCmp('tinhdiem');
                var b_chuoi1 = CH_JSON(b_kq);
                if (b_kq == "[]") {
                    var b_chuoi1 = new Array();
                    alert("Không có số liệu");
                    for (var i = 0; i < 7; i++) {
                        b_chuoi1[i] = { ma_sv: '', hoten: '', ngay_sinh: '', noi_sinh: '' };
                    }

                }

                var store = Ext.create('Ext.data.JsonStore', {
                    fields: ["ma_sv", "hoten", "ngay_sinh", "noi_sinh"],
                    data: b_chuoi1
                });

                b.bindStore(store);

                var b_chuoi1 = new Array();
                for (var i = 0; i < 7; i++) {
                    b_chuoi1[i] = { ID: '', ma_sv: '', MonID: '', tenmon: '', diem: '' };
                }
                var store = Ext.create('Ext.data.JsonStore', {
                    fields: ["ID", "ma_sv", "MonID", "tenmon", "diem"],
                    data: b_chuoi1
                });
                var b1 = Ext.getCmp('nhapdiem');
                b1.bindStore(store);
            }
        }
        function lke_diem_P_LKE(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                if (b_kq == "[]") {
                    var b_chuoi1 = new Array();
                    for (var i = 0; i < 7; i++) {
                        b_chuoi1[i] = { Id: '', MonID: '', tenmon: '', diem: '' };
                    }
                }
                var b_chuoi1 = CH_JSON(b_kq);
                var store = Ext.create('Ext.data.JsonStore', {
                    fields: ["Id", "MonID", "tenmon", "diem"],
                    data: b_chuoi1
                });
                var b = Ext.getCmp('nhapdiem');
                b.bindStore(store);
            }
        }
        function nhaodiemP_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            lke_diem_P_LKE(b_kq);
            alert("Thêm thành công");
        }
        function khoa_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {

                var b_chuoi1 = CH_JSON(b_kq);
                var a_data1 = Ext.create('Ext.data.Store', {
                    fields: ['ID', 'Ten', 'GhiChu'],
                    data: b_chuoi1
                });
                var c = Ext.getCmp('khoa_dt');
                c.bindStore(a_data1);
            }
        }
        function lophoc_nganh_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            var b_chuoi = CH_JSON(b_kq);
            var a_data = Ext.create('Ext.data.Store', {
                fields: ['id_lop', 'ten_lop'],
                data: b_chuoi
            });
            Ext.getCmp('lop').bindStore(a_data);
        }

        function khoa_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {

                var b_chuoi1 = CH_JSON(b_kq);
                var a_data1 = Ext.create('Ext.data.Store', {
                    fields: ['ID', 'Ten', 'GhiChu'],
                    data: b_chuoi1
                });
                var c = Ext.getCmp('khoa_dt');
                c.bindStore(a_data1);
            }
        }
        function lophoc_nganh_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            var b_chuoi = CH_JSON(b_kq);
            var a_data = Ext.create('Ext.data.Store', {
                fields: ['id_lop', 'ten_lop'],
                data: b_chuoi
            });
            Ext.getCmp('lophoc').bindStore(a_data);
        }
    </script>
</asp:Content>

